import threading



class RWLock:
    def __init__(self):
        self.lock = threading.Lock()
        self.cnt = 0
        self.extra = threading.Lock()

    def read_acquire(self):
        with self.extra:
            self.cnt += 1
            if self.cnt == 1:
                self.lock.acquire()

    def read_release(self):
        with self.extra:
            self.cnt -= 1
            if self.cnt == 0:
                self.lock.release()

    def write_acquire(self):
        self.lock.acquire()

    def write_release(self):
        self.lock.release()